<?php
@session_start();
//echo 'INACTIVIDAD:'.$_SESSION['inactive'];
session_cache_expire($_SESSION['inactive']/60);
$inactive = $_SESSION['inactive'];
if(isset($_SESSION['start'])){
	$session_life = time() - $_SESSION['start'];
	//echo '<br>session_life:'.$session_life;
	if($session_life > $inactive){
		unset($_SESSION['islogued']);
		$_SESSION["error"] = "El tiempo de inactividad ha caducado.<br>Vuelva a iniciar por favor.";
		//header("Location:../index.php");//logout.php
?>
		<script language="javascript">
			top.location.href= "../index.php"
		</script>
<?php
	}
}
$_SESSION['start'] = time();
if(!isset($_SESSION["usuario"])){
	header("location:../index.php"); /* Si no ha iniciado la sesion, vamos a index.php */
} else {

include_once '../util/conexion.inc';
$paso = isset($_GET['paso']) ? $_GET['paso'] : (isset($_POST['paso']) ? $_POST['paso'] : 0);
$selected = isset($_POST['parteCuerpo']) ? $_POST['parteCuerpo'] : 0;
$diagnostico = isset($_POST['diagnostico']) ? $_POST['diagnostico'] : 0;
$vWhere = " WHERE f.observacion LIKE '%%'";//".trim($diagnostico)."
if($selected > 0){
	$vWhere .= " AND f.idParte=".$selected;
}
$vJoin = "";
if($diagnostico > 0){
	$vJoin .= " LEFT JOIN diagnosticosporconsulta d ON (f.idConsulta=d.idConsulta) ";
	$vWhere .= " AND d.idEnfermedad IN (".$diagnostico.")";
}
//SELECT f.rutaAlmacenamientoFoto,f.observacion FROM fotoareaafectada f LEFT JOIN diagnosticosporconsulta d ON (f.idConsulta=d.idConsulta) WHERE d.idEnfermedad IN (1,4)
$imgQuery	=	mysql_query("SELECT f.rutaAlmacenamientoFoto,f.observacion FROM fotoareaafectada f ".$vJoin.$vWhere) or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta charset="utf-8">
<!-- <meta http-equiv="refresh" content="365"> -->
<meta name="author" content="cg">
<script language="JavaScript" src="../../jscrip/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="../carrusel/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../carrusel/js/jquery.jcarousel.min.js"></script>
<script type="text/javascript" src="../carrusel/js/thickbox.js"></script>
<link rel="stylesheet" type="text/css" href="../carrusel/css/thickbox.css"/>
<link rel="stylesheet" type="text/css" href="../carrusel/skins/ie7/skin.css"/>

<script type="text/javascript">
tb_pathToImage = "carrusel/skins/ie7/loading.gif";

var carousel_list = [
	<?php while($imgs = mysql_fetch_array($imgQuery)){?>
    		{url: "../imagenesConsultas/<?php echo $imgs['rutaAlmacenamientoFoto'];?>", title: "<?php echo utf8_encode(htmlentities($imgs['observacion']));?>"},
  <?php }?>
];

function mycarousel_itemLoadCallback(carousel, state){
    for(var i = carousel.first; i <= carousel.last; i++){
        if(carousel.has(i)){
            continue;
        }
        if(i > carousel_list.length){
            break;
        }
        var item = jQuery(mycarousel_getItemHTML(carousel_list[i-1])).get(0); // Create an object from HTML
        tb_init(item); // Apply thickbox
        carousel.add(i,item);
    }
};

function mycarousel_getItemHTML(item){ 
    var url_m = item.url.replace(/_s.jpg/g, '_m.jpg');
    return '<a href="' + url_m + '" title="' + item.title + '"><img src="' + item.url + '" width="75" height="75" border="0" alt="' + item.title + '" /></a>';
};

jQuery(document).ready(function(){
    jQuery('#mycarousel').jcarousel({
        size: carousel_list.length,
		auto: 4,
		wrap: 'last',
        itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
    });
});
</script>

<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
  $('.links legend p').hide();  
  $('.links legend').click(function() {
    $(this).next().slideToggle('fast');
  });
});
</script>
</head>

<body topmargin="0">
<table width="100%" bgcolor="#FFFFFF" align="center" border="2" cellspacing="0" cellpadding="0" class="tabla1">
<tr>
<td align="center">

<!--MODIFIQUE, texto e imagen INICIO--> 
<br />
<img src="../images/formularios/Folderimagen.png" alt="galeria" width='80' height='70' align="left"/>
<font color="#2168B6" size="4" face="Tahoma"><b>BUSQUEDA DE FOTOS DE AREA AFECTADA</b></font> 
<p>
<!--MODIFIQUE, texto e imagen INICIO--> 

<?php
if($paso == 0) {
?>
	<table border="0"  bgcolor="#91998B" cellspacing="2" style="background:#FFFFFF">
		<form method="post" name="frmGaleria" id="idFrmGaler" action="<?php echo $_SERVER['PHP_SELF'];?>">
		<div style="color:#000000;font-family:Arial;" align='center'>Seleccionar la parte del cuerpo: <?php //echo $datoMostrar; ?>
			<?php
			$sql = "SELECT idParteCuerpo, nombreparte FROM partecuerpo WHERE estadoParte=1";
			$query = mysql_query($sql) or die(mysql_error());
			?>
			<select name="parteCuerpo" id="idParteCuerpo" style="border:1px solid blue;" onChange='this.form.submit()'>
				<option value="0">--Seleccione--</option>
				<?php
				if(mysql_num_rows($query) > 0){
					while($partes = mysql_fetch_array($query)){
						$optSelected = ($partes['idParteCuerpo']==$selected) ? "selected" : "";
						echo '<option value="'.$partes['idParteCuerpo'].'" '.$optSelected.'>'.$partes['nombreparte'].'</option>';
					}
				}
				?>
			</select>
		</div>
		<p/>
		<!--div style="color:#000000;font-family:Arial;" align='center'>Ingresar un diagn&oacute;stico:	
			<input type="text" name="diagnostico" id="idDiagnostico" value="<?php /*echo @$_POST['diagnostico']; */?>" size="40px" style="border:1px solid blue;" onBlur='this.form.submit()' />
		</div-->
		
		<div style="color:#000000;font-family:Arial;" align='center'>Seleccionar un diagn&oacute;stico: <?php //echo $datoMostrar; ?>
			<?php
			$sql = "SELECT idEnfermedad,nombreEnfermedad FROM enfermedad ORDER BY nombreEnfermedad";
			$query = mysql_query($sql) or die(mysql_error());
			?>
			<select name="diagnostico" id="idDiagnostico" style="border:1px solid blue;" onChange='this.form.submit()'>
				<option value="0">--Seleccione--</option>
				<?php
				if(mysql_num_rows($query) > 0){
					$diagSelected = isset($_POST['diagnostico']) ? $_POST['diagnostico'] : 0;
					while($dt = mysql_fetch_array($query)){
						$optSelected = ($dt['idEnfermedad']==$diagnostico) ? "selected" : "";
						echo '<option value="'.$dt['idEnfermedad'].'" '.$optSelected.'>'.$dt['nombreEnfermedad'].'</option>';
					}
				}
				?>
			</select>
		</div>
		
		</form>
		<tr height="25">
			<td colspan="4"><hr></td>
		</tr>
		
		<tr>
			<td colspan="4">
				<div id="wrap" align="center">
					<h4 style="margin-left:30px;margin-right:10px; font:Arial">IMAGENES DE CONSULTAS</h4>
					<ul id="mycarousel" class="jcarousel-skin-ie7"><!-- contenido sera cargado automaticamente aqui -->
					</ul>
				</div>
			</td>
		</tr>
		
		<tr height="25">
			<td colspan="4"><hr></td>
		</tr>
		
	</table>
	<br>
	<div class="demo" align="center">
		<input type="button" value="     Reiniciar    " name="reiniciar" onClick="location.href = './galerias.php?paso=0'" />
	</div>
	<br>
<?php
}else{
	echo "Comuniquese con el administrador del sistema.";
}
?>
<br/>
</td>
</tr>
</table>
<br>
</body>
</html>
<?php
} /* Y cerramos el else */ 
?>
